$(document).ready(function(){

	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();

	if($('.calendar').length > 0){
		$('.calendar').fullCalendar({
			buttonText: {
				today: '跳转到今天',
				month: '月视图',
				week: '周视图',
				day: '日视图'
			},
			allDayText: "全天",
			timeFormat: {
				'': 'H:mm{-H:mm}'
			},
			weekMode: "variable",
			columnFormat: {
				month: 'dddd',
				week: 'dddd M-d',
				day: 'dddd M-d'
			},
			titleFormat: {
				month: 'yyyy年 MMMM月',
				week: "[yyyy年] MMMM月d日 { '&#8212;' [yyyy年] MMMM月d日}",
				day: 'yyyy年 MMMM月d日 dddd'
			},
			monthNames: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
			dayNames: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
			header: {
				left: 'prev,next,today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay',
			
			},

			editable: true,
		

		});
	
	}
	
});
function add6() {
	mini.open({
		targetWindow: window,
		url:"Conferencemanagementson.html",
		title:"新增会议室",
		height:"90%",
		width:"60%",
		showMaxButton: true,
		showModal:Boolean,
		allowResize:Boolean,
		setReadOnly:false,
		onload: function () {
			var iframe = this.getIFrameEl();//备份这个跨子页面窗口
			var data = {  action: "new"};//父传值给子页面
		},
		ondestroy: function (action) {
			if(action=="ok"){
				grid.reload();    //页面重新加载
			}
		}
	})
}
function alldata() {
	var events=[];
	$.ajax({
		url:"http://localhost:8080/DSMP/meetings/list.do",
		type:"post",
		success: function(data) {//请求成功完成后要执行的方法
			console.log(data);
			console.log(typeof data);
			data=JSON.parse(data);
			console.log(data);

			// 遍历后端日程数据
			data.Events.length && data.Events.forEach(item => {
				// 时间格式处理
				console.log('foreachItem',item.start)

				item.start = new Date(...timeCovert(item.start))
				item.end = new Date(...timeCovert(item.end))

				events.push(item)

			});
			console.log(events);
			//先清空子节点然后在渲染日历数据
			$("#boxpo").html("").append("<div class=\"box-head\">\n" +
				"\n" +
				"                    <h3>Calendar</h3>\n" +
				"\n" +
				"                </div>\n" +
				"\n" +
				"                <div class=\"box-content box-nomargin\">\n" +
				"\n" +
				"                    <div class=\"calendar\"></div>\n" +
				"\n" +
				"                </div>");

			// 日程设calendar置项，可在官网查看具体配置属性
			$('.calendar').length && $('.calendar').fullCalendar({
				buttonText: {
					today: '跳转到今天',
					month: '月视图',
					week: '周视图',
					day: '日视图'
				},
				allDayText: "全天",
				timeFormat: {
					'': 'H:mm{-H:mm}'
				},
				weekMode: "variable",
				columnFormat: {
					month: 'dddd',
					week: 'dddd M-d',
					day: 'dddd M-d'
				},
				titleFormat: {
					month: 'yyyy年 MMMM月',
					week: "[yyyy年] MMMM月d日 { '&#8212;' [yyyy年] MMMM月d日}",
					day: 'yyyy年 MMMM月d日 dddd'
				},
				monthNames: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
				dayNames: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
				header: {
					left: 'prev,next,today',
					center: 'title',
					right: 'month,agendaWeek,agendaDay',

				},

				editable: true,

				events
			});

		},
		error:function(data){
			mini.alert("cuole");
		}
	})
}
// 后端时间数据转换函数
const timeCovert = (newDateStr) => {
	console.log(newDateStr)
	// new Date(2020,02,17,14,55,04)（后端02代表2月份） ===》  new Date(2020,1,17,14,55,04) （js2月份表示法）
	let arr = newDateStr.split('(')[1].slice(0,-1).split(',')
	console.log('arr',arr)
	arr[1] = parseInt(arr[1].slice(-1)) - 1
	arr = arr.map(item => parseInt(item))
	return arr
}